<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>select</title>
	<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
	<style type="text/css">
		.search,.list{
			margin: 0px auto;
		}
	</style>
</head>
<body>
	<button class="search" id="search">查询</button>
	<table class="list"></table>
	<span></span>
<script type="text/javascript">
	$(function(){
		$(".search").on("click",function(){
			$.ajax({
				type:"GET",
				url:"http://10.222.29.173:3000/user"
			}).done(function(msg){

				$(".list").html("");
				$.each(msg,function(index,content){
					var table=$(".list");
					var tr=$("<tr></tr>");
					tr.appendTo(table);

					var td1=$("<td>"+content.id+"</td>");
					var td2=$("<td>"+content.age+"</td>");
					var td3=$("<td>"+content.name+"</td>");
					var td4=$("<button id="+content.id+" row="+index+">del</button>");

					td1.appendTo(tr);
					td2.appendTo(tr);
					td3.appendTo(tr);
					td4.appendTo(tr);
				});
				

				$("button").on("click",function(e){


					var id=$(this).attr("id");
					if(id=="search"){
						return;
					}
						
					uri="http://10.222.29.173:3000/user/"+id;
					$.ajax({
						type:"DELETE",
						url:uri,
						ContentType:"application/json"
					}).done(function(){
						
					});
					$(this).parent().empty();
				});


			});

		});

		

		// function del(){
		// 	alert("hello");
		// }

	});
</script>
</body>
</html>